from typing import Optional

from sqlalchemy import BigInteger, DateTime, Integer, PrimaryKeyConstraint, String, func
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import datetime

from config.database import Base
from utils.uuid import UUID


class CmsAlert(Base):
    __tablename__ = 'cms_alert'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='_copy_10'),
        {'comment': '告警信息'}
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, default=int(UUID().uuid()))
    state: Mapped[int] = mapped_column(Integer, comment='状态（0 失效，1 有效）')
    create_time: Mapped[datetime.datetime] = mapped_column(DateTime, comment='创建时间', server_default=func.now())
    device_id: Mapped[Optional[str]] = mapped_column(String(32), comment='设备编码')
    car_id: Mapped[Optional[str]] = mapped_column(String(32), comment='车辆编码')
    alert_type: Mapped[Optional[str]] = mapped_column(String(32), comment='告警类型')
    alert_msg: Mapped[Optional[str]] = mapped_column(String(255), comment='告警信息')
    handle: Mapped[Optional[str]] = mapped_column(String(255), comment='处理')
    create_by: Mapped[Optional[str]] = mapped_column(String(32), comment='创建人')
    update_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='修改时间',
                                                                     server_default=func.now(), onupdate=func.now())
    update_by: Mapped[Optional[str]] = mapped_column(String(32), comment='修改人')
